﻿using CCWin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor.Actions;
namespace SqlBuilder
{
    public partial class ScriptForm : Skin_Metro
    {
        public event Func<object, string, bool> SaveScriptEvent = null;
        private object _CallParam = null;
        private string _ShowScript = string.Empty;
        public ScriptForm(object obj, string showscript)
        {
            InitializeComponent();
            this._CallParam = obj;
            this._ShowScript = showscript;
            this.textEditor_BuildeJsDemo.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("JavaScript");
            this.textEditor_BuildeJsDemo.Encoding = System.Text.Encoding.Default;
            this.textEditor_BuildeJs.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy("JavaScript");
            this.textEditor_BuildeJs.Encoding = System.Text.Encoding.Default;
            this.textEditor_BuildeJs.ActiveTextAreaControl.TextArea.KeyDown += textEditor_BuildeJs_KeyDown;
            if (!string.IsNullOrEmpty(this._ShowScript))
            {
                this.textEditor_BuildeJs.Text = this._ShowScript;
            }

        }

        private void textEditor_BuildeJs_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.S)
            {
                if (SaveScriptEvent != null)
                {
                    bool issuccess = SaveScriptEvent(this._CallParam, this.textEditor_BuildeJs.Text);
                    if (issuccess)
                    {
                        MessageBoxEx.Show("修改成功", "温馨提示");
                    }
                    else
                    {
                        MessageBoxEx.Show("修改失败", "温馨提示");
                    }
                }
            }
        }
    }
}
